<?php
namespace app\blog\controller;

use think\Controller;
use app\blog\model\Users;

class User extends Controller
{
	public function index() {
		// $user_arr = [];
		// for($i = 0;$i<100;$i++){
		// 	$user_arr[$i] = [
		// 		'username' => 'admin'.$i,
		// 		'password' => md5('admin'.$i),
		// 		'email' => 'admin'.$i.'@admin.com',
		// 		'phone' => '01234567890',
		// 	];		
		// }
		
		// //return json($user_arr);
		// $user = new Users;
		// $user->saveAll($user_arr);
		
		$users = Users::where('status',1)->paginate(10);
		$page = $users->render();
		//dump($users);
 		$this->assign('users',$users);
 		$this->assign('page',$page);
 		return $this->fetch();
	}
	
	public function add() {
		$request = $this->request;
		if ($request->isPost()) {
			//dump($request->param());return ;
			$user = new Users($request->param());
			
			if ($user->allowField(true)->save()) {
				$this->success('添加成功！');
			} else $this->error($user->getError());
		}
		return $this->fetch();
	}

    public function editor($id) 
    {	
		$id = intval($id);
        $user = Users::get($id);
		if($this->request->isPost()){
			dump(input('post.'));
			// $user->save($this->request->post());
			// $this->success('修改成功');
		}        
		$this->assign('user',$user);
        return $this->fetch();

    }

	public function delete($id)
	{
		$user = Users::get($id);
		return $user->delete()?$this->success('删除成功！','/blog/user',2):$this->error($user->getError());	
	}
}

